package view;

import com.alibaba.druid.support.json.JSONUtils;
import entity.Manager;
import entity.Operator;
import service.Journal;
import service.LogServiceDaoImpl;
import tool.MyTool;

public class LogView {
    public static final String ANSI_RESET = "\u001B[0m";
    public static final String ANSI_GREEN = "\u001B[32m";
    public static final String ANSI_YELLOW = "\u001B[33m";
    public static final String ANSI_PURPLE = "\u001B[35m";
    public static final String ANSI_BLUE = "\u001B[34m";
    public static final String ANSI_CYAN = "\u001B[36m";

    LogServiceDaoImpl logServiceDao = LogServiceDaoImpl.getLogServiceDao();
    ManagerView managerView = new ManagerView();
    private static Manager manager = new Manager();
    private static Operator operator = new Operator();

    public void LogMenu() throws Exception {
        while (true) {
            System.out.println(ANSI_PURPLE);
            System.out.println("🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣");
            System.out.println("🔣                                    🔣");
            System.out.println("🔣    欢迎来到项目开发团队分配管理软件   🔣");
            System.out.println("🔣                                    🔣");
            System.out.println("🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣");
            System.out.println("🐕");
            System.out.println("🐕");
            System.out.println("🐕");
            System.out.println("🐕-----------<\uD83D\uDD23请您选择功能\uD83D\uDD23>-------------🐕");
            System.out.println("🐕-----------<\uD83D\uDC3B1.登录>-----------------🐕");
            System.out.println("🐕-----------<\uD83D\uDC182.注册或忘记密码>---------🐕");
            System.out.println("🐕-----------<\uD83E\uDD813.登录日志记录查询>-------🐕");
            System.out.println("🐕-----------<\uD83D\uDC3B4.修改密码>-------------🐕");
            System.out.println("🐕-----------<\uD83E\uDD8A5.退出>----------------🐕");
            char c = MyTool.selectMenu(5).charAt(0);
            switch (c) {
                case '1':
                    LogInView();
                    break;
                case '2':
                    ReAndFoundView();
                    break;
                case '3':
                    Journal.getRecord();
                    break;
                case '4':
                    logServiceDao.modifyPassword();
                    break;
                case '5':
                    System.exit(0);
            }
        }
    }

    public void LogInView() throws Exception {
        while (true) {
            System.out.print(ANSI_RESET + ANSI_GREEN);
            System.out.println("🔣-------~登录菜单~---------🔣");
            System.out.println("🐕-------<1.管理员登录>------*");
            System.out.println("🐖-------<2.操作员登录>------*");
            System.out.println("🐱-------<3.退出>-----------*");
            char c = MyTool.selectMenu(3).charAt(0);
            switch (c) {
                case '1':
                    Manager manager = logServiceDao.checkInManger();
                    if (manager == null)
                        return;
                    else {
                        LogView.setManager(manager);
                        managerView.managerMenu();
                    }
                    break;

                case '2':
                    Operator operator = logServiceDao.checkInOperator();
                    if (operator == null) {
                        return;
                    } else {
                        LogView.setOperator(operator);
                       OperatorFunctionView.OperatorFunctionMenu();
                    }
                case '3':
                    return;
            }
        }
    }

    public void ReAndFoundView() throws Exception {
        System.out.print(ANSI_RESET + ANSI_BLUE);
        while (true) {
            System.out.println("🔣-------~登录菜单~---------🔣");
            System.out.println("🐕-------<1.注册管理员账号>------*");
            System.out.println("🐖-------<2.找回密码>------*");
            System.out.println("🐱-------<3.退出>-----------*");
            char c = MyTool.selectMenu(3).charAt(0);
            switch (c) {
                case '1':
                    logServiceDao.registerManager();
                    break;
                case '2':
                    logServiceDao.foundPassword();
                case '3':
                    return;
            }
        }
    }

    public static Manager getManager() {
        return manager;
    }

    public static void setManager(Manager manager) {
        LogView.manager = manager;
    }

    public static Operator getOperator() {
        return operator;
    }

    public static void setOperator(Operator operator) {
        LogView.operator = operator;
    }

    public static void main(String[] args) {
        while (true) {
            LogView logView = new LogView();
            try {
                logView.LogMenu();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
